﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class PostponeTimeService : IPostponeTimeService
    {
        private IPostponeTimeDal _postTime;
        private IMapper _mapper;
        public PostponeTimeService(IPostponeTimeDal postTime, IMapper mapper)
        {
            _postTime = postTime;
            _mapper = mapper;
        }

        public async Task<int> AddPostponeTimeAsync(int postponeTime)
        {
            return await _postTime.AddAsync(new Postponetime 
            {
                PostponeTime1 = postponeTime
            });
        }

        public async  Task<int> DeletePostponeTimeAsync(int id)
        {
            var data = await _postTime.QueryAsync(id);
            return data == null ? -1 : await _postTime.DeleteAsync(data);
        }

        public async  Task<int> EditPostponeTimeAsync(int id, int postponeTime)
        {
            var data = await _postTime.QueryAsync(id);
            if (data == null)
                return -1;
            data.PostponeTime1 = postponeTime;
            return await _postTime.EditAsync(data);
        }

        public async Task<List<PostponeTimeDto>> QueryPostponeTimeAllAsync()
        {
            var data = await _postTime.QueryAsync();
            return _mapper.Map<List<Postponetime>, List<PostponeTimeDto>>(data);
        }

        public async  Task<PostponeTimeDto> QueryPostponeTimeByIdAsync(int id)
        {
            var data = await _postTime.QueryAsync(id);
            return _mapper.Map<Postponetime, PostponeTimeDto>(data);
        }
    }
}
